package com.mbyte.easy.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mbyte.easy.admin.entity.*;
import com.mbyte.easy.admin.mapper.CheckMapper;
import com.mbyte.easy.admin.mapper.VideoMapper;
import com.mbyte.easy.admin.service.*;
import com.mbyte.easy.common.constant.DraftLogConstant;
import com.mbyte.easy.common.constant.StatusRecordVideo;
import com.mbyte.easy.common.constant.StatusWriter;
import com.mbyte.easy.common.controller.BaseController;
import com.mbyte.easy.common.web.AjaxResult;
import com.mbyte.easy.security.entity.SysUser;
import com.mbyte.easy.security.service.IUserService;
import com.mbyte.easy.util.DateUtil;
import com.mbyte.easy.util.PageInfo;
import com.mbyte.easy.util.Utility;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Controller
@RequestMapping("/admin/videoLeader")
public class VideoLeaderController extends BaseController {

    @Autowired
    private IVideoService videoService;

    @Autowired
    private ICheckService checkService;

    @Autowired
    private IAllotService allotService;

    @Autowired
    private IPptService pptService;

    @Autowired
    private IUserService userService;

    @Autowired
    private VideoMapper videoMapper;
    @Autowired
    CheckMapper checkMapper;
    @Autowired
    private IGroupService groupService;

    @Autowired
    private IDraftService draftService;
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    private String prefix = "admin/video/";
    /**
     * @Author bzr
     * @Description 待抽查音转视
     * @Date 2019/12/21 23:29
     * @Param
     * @return
     **/
    @RequestMapping("unCheck")
    public String index(Model model,
                        @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                        String submitTimeSpace,
                        String allotTimeSpace,
                        Video video) {
        //这是list页面
        Page<Video> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        List<Video> lists = videoService.list(queryWrapper);
        if(!ObjectUtils.isEmpty(video.getGroupId())) {
            queryWrapper.eq("tv.group_id",video.getGroupId())
                    .in("tv.status_code",StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS);   //1023
        }else{
            queryWrapper = queryWrapper.eq("tv.group_id",null);
        }

        //所有的登录人组长的下属idList
        List<Long> childrenIdByParentId = pptService.getChildrenIdByParentId(pptService.getUserByUserName(Utility.getCurrentUsername()).getId());
        //IdList与t_group表的userId所对应。

        QueryWrapper<Group> groupQueryWrapper=new QueryWrapper<>();
        List<Group> groupList = groupService.list(groupQueryWrapper);
        if (!CollectionUtils.isEmpty(groupList)) {
        if (childrenIdByParentId!=null){
            groupQueryWrapper=groupQueryWrapper.in("user_id",childrenIdByParentId);
        }}
        //获取groupList

        //查询一个组的长度
        QueryWrapper<Video> videoGroup =new QueryWrapper<>();
        videoGroup.eq("group_id",video.getGroupId());

        List<Video> videoList1 = videoService.list(videoGroup);
        //这是组编号的回显
        QueryWrapper<Video> videoQueryWrapper=new QueryWrapper<>();
        videoQueryWrapper.in("status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS);
        videoQueryWrapper.eq("draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
        videoQueryWrapper.groupBy("group_id");
        List<Video> videoList=videoService.list(videoQueryWrapper);
        for(Video video1:videoList){
            for (Group group : groupList) {
                if(video1.getGroupId().equals(group.getGroupId())){
                    video1.setGroupName(group.getName());
                }
            }
        }


        queryWrapper.ne("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED);//显示2025

        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        model.addAttribute("videoList", videoList);
        model.addAttribute("videoListSize", draftService.getNeedCheckSizeVideo(video.getGroupId(),false,
                StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));//1025
        return prefix+"both/unCheck";
    }


     /**
     * @Author 刘辉
     * @Description 待抽查录屏--录屏课程负责人
     * @Date 2019/12/21 23:29
     * @Param
     * @return
     **/
    @RequestMapping("unCheckAUDIOVIDEO")
    public String unCheckAUDIOVIDEO(Model model,
                        @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                        String submitTimeSpace,
                        String allotTimeSpace,
                         Video video) {

        //这是list页面
        Page<Video> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS);
        //这是组编号的回显
        QueryWrapper<Video> videoQueryWrapper=new QueryWrapper<>();
        videoQueryWrapper.eq("status_code",StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS);
        log.info("======videoQueryWrapper第一阶段=========>>>>{}",videoService.list(videoQueryWrapper));
        videoQueryWrapper.groupBy("group_id");
        log.info("======videoQueryWrapper第二阶段=========>>>>{}",videoService.list(videoQueryWrapper));
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        QueryWrapper<Video> videos = new QueryWrapper<>();
        videos.eq("group_id",video.getGroupId());
        List<Video> list = videoService.list(videos);

        //所有的登录人组长的下属idList
        List<Long> childrenIdByParentId = pptService.getChildrenIdByParentId(pptService.getUserByUserName(Utility.getCurrentUsername()).getId());
        //IdList与t_group表的userId所对应。
        QueryWrapper<Group> groupQueryWrapper=new QueryWrapper<>();
        if (childrenIdByParentId!=null){
            childrenIdByParentId.add(-1L);
            groupQueryWrapper=groupQueryWrapper.in("user_id",childrenIdByParentId);
        }

        //获取groupList
        List<Group> groupList = groupService.list(groupQueryWrapper);
        List<String> stringList=new ArrayList<>(groupList.size());
        QueryWrapper qw = new QueryWrapper<>();
        if (!CollectionUtils.isEmpty(groupList)) {
            //获取GroupList的group_id字段
            for (int i = 0; i < groupList.size(); i++) {
                stringList.add(groupList.get(i).getGroupId());
            }
            queryWrapper = queryWrapper.in("tv.group_id", stringList);
        }
        List<Video> videoList=videoService.list(videoQueryWrapper);
        if (videoList!=null){
            for (Video video1 : videoList) {
                for (Group group : groupList) {
                    if(video1.getGroupId().equals(group.getGroupId())){
                        video1.setGroupName(group.getName());
                    }
                }
            }
             model.addAttribute("videoListSize", draftService.getNeedCheckSize(video.getGroupId()
                    ,false,StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS,
                     StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS,
                     StatusRecordVideo.STATUS_RECORD_COURSEREADER_FAILED,
                     StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS,
                     StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS));//除1029
            model.addAttribute("videoList", videoList);
        }else{
            model.addAttribute("videoList", 0);
        }
        if(!ObjectUtils.isEmpty(video.getGroupId())){
            queryWrapper = queryWrapper.eq("tv.group_id",video.getGroupId());
        }else {
            queryWrapper.in("group_id", stringList);
            QueryWrapper<Video> pptQueryWrapper = new QueryWrapper<>();
            pptQueryWrapper.eq("status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoService.page(page, pptQueryWrapper);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/unCheckAudioVideo";
        }
        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"leader/unCheckAudioVideo";
    }


    /**
     * 张雪
     * 批量抽查校对--音转视
     * @param id
     * @return
     */
    @GetMapping("leaderVpass")
    @ResponseBody
    public AjaxResult leaderVpass(@RequestParam("id") Long id){
        log.info("通过抽查id-->{}",id);
        Video videoPass = new Video();
        videoPass.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//1025音频校对组长通过
                .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setIsPass(true).setId(id);
        videoService.updateById(videoPass);
        Check videoCheck = new Check();
        videoCheck.setIsPass(true).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)//1023音频校对人通过音转视
                .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//1025音频校对组长通过
                .setDraftId(videoService.getById(id).getDraftId());
        checkService.save(videoCheck);
        log.info("update-->{}",videoPass.toString());
        return toAjax(true);
    }

    /**
     * @Author 张雪
     * @Description 跳转页面
     * 音视频校对组长  驳回  填写理由
     * @Date 2019/12/23 15:11
     * @Param
     * @return
     **/
    @RequestMapping("leaderToReason")
    public String leaderToReason(Long id,Model model){
        log.info("id====>{}",id);
        model.addAttribute("id",id);
        return prefix+"both/reason";
    }

    /**
     * @Author 张雪
     * @Description 音视频校对组长  抽查拒绝  音转视
     * @Date 2019/12/23 15:13
     * @Param
     * @return
     **/
    @PostMapping("leaderRefuse")
    @ResponseBody
    public AjaxResult leaderRefuse(Long id,String reason,String draftTitle,String draftText,Long draftNum,String fileName){
        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        log.info("拒绝id-->{}",id);
        Video videoRefuse = new Video();
        videoRefuse.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)//2025音视频校对组长拒绝
                .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setIsPass(false).setId(id);
        videoService.updateById(videoRefuse);
        Check videoCheck = new Check();
        videoCheck.setIsPass(false).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)//1023
                .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)//2025
                .setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now())
                .setReason(reason).setDraftId(videoService.getById(id).getId());
        checkService.save(videoCheck);
        log.info("update-->{}",videoRefuse.toString());

        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                .setDraftId(videoService.getById(id).getDraftId()).setReason(reason)
                .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)
                .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)
                .setGroupId(videoService.getById(id).getGroupId()));
        return toAjax(true);
    }

    /**
     * @Author 刘辉
     * @Description 录屏课程负责人  抽查拒绝  录屏
     * @Date 2019/12/23 15:13
     * @Param
     * @return
     **/
    @PostMapping("leaderPptRefuse")
    @ResponseBody
    public AjaxResult leaderPptRefuse(Long id,String reason,String draftTitle,String draftText,Long draftNum,String fileName){

        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        log.info("拒绝id-->{}",id);
        Video videoRefuse = new Video();
        videoRefuse.setStatusCode(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_FAILED)//2029录屏课程负责人拒绝
                .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setIsPass(false).setId(id);
        videoService.updateById(videoRefuse);
        Check videoCheck = new Check();
        videoCheck.setIsPass(false).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setPreStatusCode(StatusRecordVideo.STATUS_RECORD_PPTTORECORD_UPLOADTO)//1027
                .setOverStatusCode(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_FAILED)//2029
                .setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now())
                .setReason(reason).setDraftId(videoService.getById(id).getId());
        checkService.save(videoCheck);
        log.info("update-->{}",videoRefuse.toString());

          applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                    .setDraftId(videoService.getById(id).getDraftId())
                    .setGroupId(videoService.getById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_FAILED)
                    .setReason(reason));

        return toAjax(true);
    }




    /**
     * @Author 张雪
     * @Description 音视频校对组长  已被抽查驳回的音转视
     * @Date 2019/12/23 14:57
     * @Param
     * @return
     **/
    @RequestMapping("refusedLeader")
    public String refusedLeader(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video,
                                String groupIIID) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        SysUser sysUser = videoService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = videoService.getAllotDraftIdByUserId(sysUser.getId());
        log.info("=================="+groupByUserId);
        if (groupByUserId.size() != 0) {
            queryWrapper.in("tv.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            //分配表中被分配人id为自己的draftIds
            queryWrapper.eq("tv.draft_type", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
            queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED);//2025音视频校对组长拒绝
            IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            //model.addAttribute("allotTimeSpace", allotTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "both/refusedLeader";
        }else{
            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
            IPage<Video> pageInfo = videoService.page(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
           // model.addAttribute("allotTimeSpace", allotTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "both/refusedLeader";
        }
    }

    /**
     * @Author 刘辉
     * @Description 录屏课程负责人  已驳回的录屏
     * @Date 2019/12/23 14:57
     * @Param
     * @return
     **/
    @RequestMapping("refusedAUDIOVIDEO")
    public String refusedAUDIOVIDEO(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();

        if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }


        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdUnPass(sysUser.getId());
        if(groupByUserId.size()!=0){
            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_FAILED);//2025音视频校对组长拒绝
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/refusedAUDIOVIDEO";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/refusedAUDIOVIDEO";
        }
    }




    /**
     * @Author 张雪
     * @Description 音视频校对组长  已抽查通过的音转视
     * @Date 2019/12/23 14:57
     * @Param
     * @return
     **/
    @RequestMapping("overLeader")
    public String overLeader(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video,
                                String groupIIID) {
        Page<Video> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);

        SysUser sysUser = videoService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = videoService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.in("tv.draft_id", groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1025音视频校对组长通过
            queryWrapper.eq("tv.draft_type", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
            IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("allotTimeSpace", allotTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "both/overVideo";
        }else{
            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
            IPage<Video> pageInfo = videoService.page(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("allotTimeSpace", allotTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "both/overVideo";
        }
    }

     /**
     * @Author 刘辉
     * @Description 录屏课程负责人--  已通过的录屏
     * @Date 2019/12/31
     * @Param
     * @return
     **/
    @RequestMapping("overAUDIOVIDEO")
    public String overAUDIOVIDEO(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video
                                ) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();

       if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }



        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdPass(sysUser.getId());

        if(groupByUserId.size()!=0){
            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS);//1029音视频校对组长通过
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);



            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/overAduioVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/overAduioVideo";
        }
    }




    /**
     * @Author 张雪
     * @Description 音视频校对组长  批量通过
     * @Date 2019/12/23 15:27
     * @Param
     * @return
     **/
    @RequestMapping("passAllvideo")
    @ResponseBody
    public AjaxResult passAllVideo(String idsStr){
        String[] ids = idsStr.substring(0,idsStr.length()-1).split(",");

        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        Video video = new Video();
        video.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1025
        video.setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()));
        video.setIsPass(true);
        queryWrapper.in("id",ids);
        videoService.update(video, queryWrapper);

        for (int i = 0; i < ids.length; i++) {
            Check check = new Check();
            check.setIsPass(true);
            check.setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS);//1023
            check.setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1025
            check.setDraftId(videoService.getOne(new QueryWrapper<Video>().eq("id", Long.valueOf(ids[i]))).getId());
            videoService.insertCheck(check);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId(videoService.getById(ids[i]).getDraftId())
                    .setGroupId(videoService.getById(ids[i]).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));
        }
        return toAjax(true);
    }




    /**
     * 刘辉
     *   录屏课程负责人 批量通过
     * @param ids
     * @param model
     * @param allot
     * @return
     */

    @RequestMapping("passPptAll")
    @ResponseBody
    public AjaxResult passPptAll(String ids, Model model, Allot allot){
        log.info("===================组长分配成功+++++++++");
        Long currentUserid = allotService.selectUserIdByUsername(Utility.getCurrentUsername());
        String idsList[] = ids.split(",");
        log.info("ddddddddddddd"+idsList);
        //String数组转成long型
        Long[] arrayIds = new Long[idsList.length];
        for (int i = 0; i <idsList.length ; i++) {
            arrayIds[i] = Long.parseLong(idsList[i]);
        }
        List<Video> videoList = new ArrayList<>();
        List<Check> checkList = new ArrayList<>();
        for (int i = 0; i <arrayIds.length ; i++) {
           //得到实体list
            Video video = new Video();
            video.setStatusCode(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS)//1029
                        .setLastOperator(currentUserid).setIsPass(true);
            video.setId(arrayIds[i]);
            videoList.add(video);

            Group group = new Group();
            group.setUserId(currentUserid);
            groupService.updateById(group);


            Check videoCheck = new Check();
            videoCheck.setIsPass(true).setUserId(currentUserid)
                    .setPreStatusCode(StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS)//1028
                    .setOverStatusCode(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS)//1029
                    .setDraftId(videoService.getById(arrayIds[i]).getDraftId())
            .setUpdateTime(LocalDateTime.now())
            .setCreateTime(LocalDateTime.now());
            checkService.save(videoCheck);

               applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId(videoService.getById(arrayIds[i]).getDraftId())
                    .setGroupId(videoService.getById(arrayIds[i]).getGroupId())
                    .setActionContent("录屏课程负责人审核通过录屏稿件")
                    .setPrimaryState(StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS));
        }
        videoService.updateBatchById(videoList);



        return toAjax(true);
    }

    /**
     * 音视频校对组长 --批量通过-- 录屏
     * 刘辉
     * @param ids
     * @param model
     * @param allot
     * @return
     */
    @RequestMapping("passAll")
    @ResponseBody
    public AjaxResult passAll(String ids, Model model, Allot allot){
        log.info("===================组长分配成功+++++++++");
        Long currentUserid = allotService.selectUserIdByUsername(Utility.getCurrentUsername());
        String idsList[] = ids.split(",");
        log.info("ddddddddddddd"+idsList);
        //String数组转成long型
        Long[] arrayIds = new Long[idsList.length];
        for (int i = 0; i <idsList.length ; i++) {
            arrayIds[i] = Long.parseLong(idsList[i]);
        }
        List<Video> videoList = new ArrayList<>();
        List<Check> checkList = new ArrayList<>();
        for (int i = 0; i <arrayIds.length ; i++) {
            //得到实体list
            Video video = new Video();
            video.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//1025
                    .setLastOperator(currentUserid).setIsPass(true);
            video.setId(arrayIds[i]);
            videoList.add(video);

            Check videoCheck = new Check();
            videoCheck.setIsPass(false).setUserId(currentUserid)
                    .setPreStatusCode(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)//1038
                    .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//2025
                    .setDraftId(videoService.getById(arrayIds[i]).getDraftId())
                    .setUpdateTime(LocalDateTime.now())
                    .setCreateTime(LocalDateTime.now());
            checkMapper.updateByDraftId(videoCheck);

             applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId(videoService.getById(arrayIds[i]).getDraftId())
                    .setGroupId(videoService.getById(arrayIds[i]).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));
        }
        videoService.updateBatchById(videoList);

        return toAjax(true);
    }


    //视频终审人
    /**
     *视频终审人抽查
     * 待抽查视频
     */
    @RequestMapping("unCheckVideo")
    public String unCheckVideo(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getGroupId())){
            queryWrapper = queryWrapper.eq("group_id",video.getGroupId());
        }

        //查询一个组的长度
        QueryWrapper<Video> videoGroup =new QueryWrapper<>();
        videoGroup.eq("group_id",video.getGroupId());
        List<Video> videoList1 = videoService.list(videoGroup);

        queryWrapper.eq("status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1025音视频校对组长拒绝
        QueryWrapper<Video> videos = new QueryWrapper<>();
        videos.eq("status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);
        videos.groupBy("group_id");
        //分配表中被分配人id为自己的draftIds
        List<Video> videoList=videoService.list(videos);
        for(Video video1:videoList){
            log.info("videoD================================={}",video1);
            QueryWrapper<Group> wrapper = new QueryWrapper<>();
            wrapper.eq("group_id",video1.getGroupId());
            Group group = groupService.getOne(wrapper);
            video1.setGroupName(group.getName());
             model.addAttribute("videoListSize", draftService.getNeedCheckSize(video1.getGroupId(),
                     StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS
            ));
        }
        log.info("videoSize是"+videoList1.size());
        IPage<Video> pageInfo = videoService.page(page, queryWrapper);
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);

      //wangyan 显示制作人名称
        List<Video> draftList = videoMapper.selectList(queryWrapper);
        Map<Long,String> types = new HashMap<Long,String>();
        List<Long> ids = new ArrayList<>();
        for(Video video1:draftList){
            if(!ids.contains(video1.getVideoMaker())) {
                ids.add(video1.getVideoMaker());
                types.put(video1.getVideoMaker(), userService.selectByPrimaryKey(video1.getVideoMaker()).getUsername());
            }
        }
        model.addAttribute("name",types);

         //稿件标题+文件名
            Map<Long,String> amap=new HashMap<>();
            Map<Long,String> filemap=new HashMap<>();
            List<Video> list2 = videoService.list(queryWrapper);
            for (int i = 0; i < list2.size(); i++) {
                amap.put(list2.get(i).getId(),draftService.getById(list2.get(i).getDraftId()).getDraftTitle());
                filemap.put(list2.get(i).getId(),draftService.getById(list2.get(i).getDraftId()).getFileName());
            }
            model.addAttribute("map",amap);
            model.addAttribute("filemap",filemap);

            //组名
            List<Video> list1 = videoService.list(queryWrapper);
            Map<String,String> groupMap=new HashMap<>();
            for (int i = 0; i < list1.size(); i++) {
                String name = groupService.getNameByGroupId(list1.get(i).getGroupId());
                groupMap.put(list1.get(i).getGroupId(),name);
            }
            log.info("============list1========="+list1);
            log.info("============mao========="+groupMap);
            model.addAttribute("groupMap", groupMap);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        if(!ObjectUtils.isEmpty(video.getGroupId())&&video.getGroupId()!=""){
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
        }else {
            log.info("进123");
            queryWrapper.eq("status_code","99999");
            model.addAttribute("pageInfo",new PageInfo(videoService.page(page,queryWrapper)));
        }
        model.addAttribute("videoList", videoList);
        model.addAttribute("videoListSize",videoList1.size());
        return prefix+"Boss/unCheckVideo";

    }

    /**
     * @Author 张雪
     * @Description 终审人  批量通过
     * @Date 2019/12/23 15:27
     * @Param
     * @return
     **/
    @PostMapping("passAllVideo")
    @ResponseBody
    public AjaxResult passAllVideo(@RequestBody List<Long> ids){
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        queryWrapper.in("id",ids);
        Video video = new Video();
        video.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS);
        video.setLastOperator(pptService.selectIdByUsername(Utility.getCurrentUsername()));
        video.setIsPass(false);
        video.setUpdateTime(LocalDateTime.now());
        videoService.update(video,queryWrapper);

        List<Check> checks = new ArrayList<>();
        for (int i = 0; i < ids.size(); i++){
            Check check = new Check();
            check.setDraftId(videoService.getById(ids.get(i)).getDraftId());
            check.setUserId(pptService.selectIdByUsername(Utility.getCurrentUsername()));
            check.setIsPass(false);
            check.setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);
            check.setCreateTime(LocalDateTime.now());
            check.setUpdateTime(LocalDateTime.now());
            check.setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS);
            checks.add(check);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId(videoService.getById(ids.get(i)).getDraftId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS)
                    .setGroupId(videoService.getById(ids.get(i)).getGroupId()));

        }
        checkService.saveBatch(checks);

        return toAjax(true);
    }


/**
 * 终审人已驳回
 *@author 孙祺至 刘辉
 *@date 2019/12/30 17:23
 */
    @RequestMapping("failedCheck")
    public String index(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);
        queryWrapper.eq("tv.last_operator",pptService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);


        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"Boss/failedCheck";
    }

    @GetMapping("failedReasonBefore/{id}")
    public String failedReasonBefore(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = pptService.getCheckById(id);
        log.info("==========id======="+id);
        log.info("==========checkById======="+checkById);
        for (int i = 0; i < checkById.size(); i++) {
            if (videoService.getById(id).getLastOperator()==checkById.get(i).getUserId()
                    &&checkById.get(i).getIsPass()==true){
                log.info("=========jinlaile ======"+ checkById.get(i).getReason()+i);
                model.addAttribute("check", checkById.get(i).getReason());
                return prefix + "FailedReasonBefore";
            }
        }
        return prefix + "FailedReasonBefore";
    }

    /**
     * 刘辉
     * 终审人---已通过
     * @param model
     * @param submitTimeSpace
     * @param pageNo
     * @param pageSize
     * @param video
     * @return
     */
    @RequestMapping("auviLeaderSuccess")
    public String auviLeaderSuccess(Model model,
                                    String submitTimeSpace,
                                    @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                    Video video){
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();

        if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS);
        queryWrapper.eq("tv.last_operator",pptService.selectIdByUsername(Utility.getCurrentUsername()));
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);


        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("submitTimeSpace",submitTimeSpace);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        model.addAttribute("searchInfo",video);
        return prefix+"Boss/successReviewed";
    }






    @RequestMapping("AuViLeaderfailedBefore/{ids}")
    public String AuViLeaderfailedBefore(Model model,@PathVariable("ids") Long ids){
        model.addAttribute("ids",ids);
        return prefix+"Boss/AuViLeaderfailedBefore";
    }

    /**
     * 音视频终审人拒绝 --牛英健--刘辉--
     * @param reason
     * @param id
     * @param draftTitle
     * @param draftText
     * @param draftNum
     * @param fileName
     * @return
     */
    @RequestMapping("AuViLeaderFailedReason")
    @ResponseBody
    public AjaxResult AuViLeaderFailedReason(String reason,Long id,String draftTitle,String draftText,Long draftNum,String fileName){
        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        log.info("id"+id);
        Video video= videoService.getById(id);
        video.setId(id);
        video.setUpdateTime(LocalDateTime.now());
        video.setLastOperator(pptService.selectIdByUsername(Utility.getCurrentUsername()));
        video.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);
        video.setIsPass(false);
        videoService.updateById(video);

        Check check = new Check();
        check.setDraftId(id);
        check.setUserId(pptService.selectIdByUsername(Utility.getCurrentUsername()));
        check.setIsPass(false);
        check.setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);
        check.setCreateTime(LocalDateTime.now());
        check.setUpdateTime(LocalDateTime.now());
        check.setReason(reason);
        check.setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);
        checkService.save(check);

        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                .setDraftId(videoService.getById(id).getDraftId())
                .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)
                .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
                .setGroupId(videoService.getById(id).getGroupId())
                .setReason(reason));
        return toAjax(true);
    }

    @GetMapping("failedBefore/{id}")
    public String failedAll(@PathVariable("id") Long id, Model model) {
        log.info("===========failedBefore=============>{}", id);
        model.addAttribute("id", id);
        return prefix + "VSectionLeaderFailedReason";
    }



//音视频校对组长处理录屏

     /**
     * @Author 刘辉
     * @Description 待抽查录屏--音视频校对组长
     * @Date 2019/12/21 23:29
     * @Param
     * @return
     **/
    @RequestMapping("unCheckPptVideo")
    public String unCheckPptVideo(Model model,
                        @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                        String submitTimeSpace,
                        String allotTimeSpace,
                         Video video) {

          //这是list页面
        Page<Video> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS);//1038
        //这是组编号的回显
        QueryWrapper<Video> videoQueryWrapper=new QueryWrapper<>();
        videoQueryWrapper.eq("status_code",StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS);//1038
        videoQueryWrapper.groupBy("group_id");
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);

        QueryWrapper<Video> videos = new QueryWrapper<>();
        videos.eq("group_id",video.getGroupId());
        videos.eq("status_code", StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS);
        List<Video> list = videoService.list(videos);

        //所有的登录人组长的下属的id
        List<Long> childrenIdByParentId = pptService.getChildrenIdByParentId(pptService.getUserByUserName(Utility.getCurrentUsername()).getId());
        //IdList与t_group表的userId所对应。
        QueryWrapper<Group> groupQueryWrapper=new QueryWrapper<>();
        if (childrenIdByParentId!=null){
            childrenIdByParentId.add(-1L);
            groupQueryWrapper=groupQueryWrapper.in("user_id",childrenIdByParentId);
        }
        //获取groupList
        List<Group> groupList = groupService.list(groupQueryWrapper);
        log.info("=======groupList============"+groupList);
        List<String> stringList=new ArrayList<>(groupList.size());
        if (!CollectionUtils.isEmpty(groupList)) {
            log.info("====================" + stringList);
            //获取GroupList的group_id字段
            for (int i = 0; i < groupList.size(); i++) {
                stringList.add(groupList.get(i).getGroupId());
            }
            queryWrapper = queryWrapper.in("tv.group_id", stringList);
        }
        List<Video> videoList=videoService.list(videoQueryWrapper);
        if (videoList!=null){
            for (Video video1 : videoList) {
                for (Group group : groupList) {
                    if(video1.getGroupId().equals(group.getGroupId())){
                        //设置video的groupname等于Group表的name
                        video1.setGroupName(group.getName());
                    }
                }
                model.addAttribute("videoListSize", draftService.getNeedCheckSizeVideo(video1.getGroupId()
                    ,false,
                     StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));//除去1025
            }

            model.addAttribute("videoList", videoList);
        }else{
            model.addAttribute("videoList", 0);
        }

        if(!ObjectUtils.isEmpty(video.getGroupId())){
            queryWrapper = queryWrapper.eq("tv.group_id",video.getGroupId());
        }else {
            queryWrapper.in("tv.group_id", stringList);
            QueryWrapper<Video> pptQueryWrapper = new QueryWrapper<>();
            pptQueryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, pptQueryWrapper);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/pptVideo/unCheckPptVideo";
        }
        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"leader/pptVideo/unCheckPptVideo";
    }


      /**
     * @Author 刘辉
     * @Description 音视频校对组长 --  已通过的录屏
     * @Date 2019/02/06
     * @return
     **/
 @RequestMapping("overPptVideo")
    public String overPptVideo(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video
                                ) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();

         if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdPass(sysUser.getId());

        if(groupByUserId.size()!=0){

            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1025音视频校对组长通过
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);


            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/pptVideo/overPptVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/pptVideo/overPptVideo";
        }
    }

 /**
     * @Author 刘辉
     * @Description 音视频校对组长  已驳回的录屏
     * @Date 2019/12/23 14:57
     * @Param
     * @return
     **/
    @RequestMapping("refusedPptVideo")
    public String refusedPptVideo(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace,
                                String allotTimeSpace,
                                Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper();
         if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }



        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdUnPass(sysUser.getId());
        if(groupByUserId.size()!=0){
            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED);//2025音视频校对组长拒绝
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);


            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/pptVideo/refusedPptVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"leader/pptVideo/refusedPptVideo";
        }
    }


     /**
     * @Author 刘辉
     * @Description 被驳回录屏----音视频校对组长
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refuseBossPptVideo")
    public String refuseBossVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdUnPass(sysUser.getId());
        if (groupByUserId.size() != 0) {
            queryWrapper.eq("tv.draft_type", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);
            queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);


            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/pptVideo/refuseBossPptVideo";
        } else {
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "leader/pptVideo/refuseBossPptVideo";
        }
    }
 }